--览阅千卷
local lanyueqianjuan = fk.CreateSkill {
    name = "mcdh_lanyueqianjuan",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

lanyueqianjuan:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self)  then return false end
        local room = player.room
        local logic = room.logic
        for _, move in ipairs(data) do
            if move.from == player then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand then
                        local events = logic:getEventsOfScope(GameEvent.MoveCards, 3, function(e)
                            for _, move in ipairs(e.data) do
                               
                                if move.from == player and not (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
                                    return table.find(move.moveInfo, function(info)
                                        return (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) 
                                    end)
                                end
                            end
                        end, Player.HistoryTurn)
                        return #events == 3 and events[3].data == data
                    end
                end
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        local cards = room:getNCards(3)
        local data = room:askToYiji(player,{min_num=3,max_num=3,skill_name=lanyueqianjuan.name,prompt="#lanyueqianjuan"})
        room:doYiji(data,player,lanyueqianjuan.name)
    end,
})

Fk:loadTranslationTable {
    ["mcdh_lanyueqianjuan"] = "览阅千卷",
    [":mcdh_lanyueqianjuan"] = "『览阅千卷』<br>你于每回合内第三次失去牌后，你观看并分配牌堆顶三张牌。",
    ["#lanyueqianjuan"] = "览阅千卷：分配这些牌"
}

return lanyueqianjuan